﻿using System;

namespace CQRS.Reports.SqlQueryBuilder
{
    public class SqlUpdateStatementBuilder : ISqlUpdateStatementBuilder
    {
        #region ISqlUpdateStatementBuilder Members

        public string GetUpdateString<TDto>(QueryCriteria updateCriteria, QueryCriteria whereCriteria)
            where TDto : Report
        {
            if (updateCriteria == null)
                throw new ArgumentNullException("updateCriteria");

            if (whereCriteria == null)
                throw new ArgumentNullException("whereCriteria");

            if (! updateCriteria.IsNotEmpty)
                throw new ArgumentNullException("updateCriteria");

            if (!whereCriteria.IsNotEmpty)
                throw new ArgumentNullException("whereCriteria");

            string tableName = typeof (TDto).Name;

            return string.Format("UPDATE {0} SET {1} WHERE {2};",
                                 tableName,
                                 updateCriteria.GenerateQueryString("update_"),
                                 whereCriteria.GenerateQueryString());
        }

        #endregion
    }
}